<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="lib/css/bootstrap.css">
    <title>注册</title>
    <style>
        .container-box {
            margin-top: 70px;
        }
    </style>
</head>

<body>

    <nav class="navbar navbar-inverse navbar-fixed-top">
        <div class="container">
            <div class="navbar-header">
                <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false"
                    aria-controls="navbar">
                    <span class="sr-only">Toggle navigation</span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                    <span class="icon-bar"></span>
                </button>
                
            </div>
            <div id="navbar" class="collapse navbar-collapse">
                <ul class="nav navbar-nav">
                    <li class="active"><a href="#">注册页面</a></li>
                   
                </ul>

            </div>
            
        </div>
    </nav>

    <div class="container container-box">
       
        <form>
            <div class="form-group">
                <label for="username">用户名：</label>
                <input type="text" class="form-control" name="username" id="username">
            </div>
            <div class="form-group">
                <label for="psw">密码：</label>
                <input type="password" class="form-control" name="psw" id="psw">
            </div>
            <div class="form-group">
                <label for="confirm">确认密码：</label>
                <input type="password" class="form-control" id="confirm">
            </div>
            <label for="">性别：</label>
            <div>
                <label for="male" class="radio-inline">
                    <input type="radio" name="sex" id="male" value="true" checked>先生
                </label>

                <label for="female" class="radio-inline">
                    <input type="radio" name="sex" id="female" value="false">女士
                </label>
            </div>
            <div class="form-group">
                <label for="email">邮箱：</label>
                <input type="email" class="form-control" name="email" id="email">
            </div>
            <div>
                <label for="course">专业：</label>
                <select name="course" id="course" class="form-control">
                    <option value="HTML" selected>HTML</option>
                    <option value="JAVA">JAVA</option>
                    <option value="PHP">PHP</option>
                    <option value="大数据">大数据</option>
                </select>
            </div>
            <div class="modal-footer">
                <input type="submit" class="btn btn-primary btn-lg save" value="注册">
            </div>
        </form>
    </div>


    <script src="lib/jquery.js"></script>
    <script src="lib/js/bootstrap.js"></script>

    <script>
        $("form").submit(function (e) {
            e.preventDefault();
            
            var pwd = $(":password");
            if(pwd.first().val() == pwd.eq(1).val()){
                $.post("/regist",$(this).serialize(),(res)=>{
                    console.log(res);
                    if(res.code == "success"){
                        location.href = "login.html";
                    }else{
                        alert(res.msg);
                    }
                })
            }else{
                alert("两次密码不一致，请检查后再注册")
            }
        })
    </script>
</body>

</html>